home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
jwpsrc.zip
/
INPUT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
40KB
|
1,442 lines
/* Copyright (C) Stephen Chung, 1991-1993. All rights reserved. */
#include "jwp.h"
#define STACKDEPTH 50
/*
#define tolower(x) AnsiLower ((LPSTR) (LONG) (BYTE) (x))
#define toupper(x) AnsiUpper ((LPSTR) (LONG) (BYTE) (x))
*/
#define tolower(x) (('A' <= (x) && (x) <= 'Z') ? (x) + 32 : (x))
#define toupper(x) (('a' <= (x) && (x) <= 'a') ? (x) - 32 : (x))
#define islower(x) ('a' <= (x) && (x) <= 'z')
#define isupper(x) ('A' <= (x) && (x) <= 'Z')
#define isalpha(x) (isupper(x) || islower(x))
static char Typed[10] = "";
static char Temp[10] = "";
static KANJI InputBuffer[10];
static KANJI KanjiBuffer[MAXLINELEN];
static KANJI LastConv[MAXLINELEN];
BYTE LastConvKey[256];
static int LastLen;
static struct {
int offset;
int length;
} GlossaryStack[STACKDEPTH];
static int Stackp = 0;
typedef struct {
int state;
char *input;
int next;
} STATE;
/* The State Machine */
static STATE states[] = {
{ 0, "aiueo", -1 }, /* Start */
{ 0, "hmzbpr", 1 },
{ 0, "kg", 30 },
{ 0, "y", 27 },
{ 0, "n", 3 },
{ 0, "j", 4 },
{ 0, "t", 5 },
{ 0, "d", 6 },
{ 0, "s", 7 },
{ 0, "c", 8 },
{ 0, "w", 9 },
{ 0, "v", 13 },
{ 0, "f", 14 },
{ 0, "+", 24 },
{ 0, "`", -1 },
{ 0, "'", -1 },
{ 0, "", -1 },
{ 1, "aiueo", -1 }, /* {khmgjdbpr} */
{ 1, "y", 2 },
{ 2, "aueo", -1 }, /* [...]y */
{ 3, "y", 2 }, /* n */
{ 3, "aiueo'", -1 },
{ 4, "y", 2 }, /* j */
{ 4, "aiueo", -1 },
{ 5, "y", 2 }, /* t */
{ 5, "aiueo", -1 },
{ 5, "sz", 10 },
{ 5, "c", 28 },
{ 6, "aiueo", -1 }, /* d */
{ 6, "y", 11 },
{ 7, "y", 2 }, /* s */
{ 7, "aiueo", -1 },
{ 7, "h", 12 },
{ 8, "y", 2 }, /* c */
{ 8, "h", 12 },
{ 8, "i", -1 },
{ 8, "/", -1 },
{ 9, "aieo", -1 }, /* w */
{ 10, "u", -1 }, /* t{sz} */
{ 11, "ui", -1 }, /* dy */
{ 12, "aiueo", -1 }, /* ch, sh */
{ 13, "aiueo", -1 }, /* v */
{ 14, "aiueo", -1 }, /* f */
{ 14, "-", -1 },
{ 22, "`", -1 }, /* ` */
{ 23, "'", -1 }, /* ' */
{ 24, "aiueo", -1 }, /* + */
{ 24, "t", 25 },
{ 24, "y", 2 },
{ 24, "w", 29 },
{ 25, "u", -1 }, /* +t */
{ 25, "sz", 26 },
{ 26, "u", -1 }, /* +t{sz} */
{ 27, "aueo", -1 }, /* y */
{ 27, "=", -1 },
{ 28, "y", 2 }, /* tc */
{ 28, "h", 12 },
{ 28, "i", -1 },
{ 29, "a", -1 }, /* +w */
{ 30, "aiueo", -1 }, /* {kg}.. */
{ 30, "y", 2 },
{ 30, "w", 31 },
{ 31, "aieo", -1 }, /* {kg}{uw}.. */
{ -999, NULL, -1 }
};
/* The Conversion Tables */
static struct {
char ascii;
KANJI kanji;
} JAsciiEquivalents[] = {
{ ' ', 0x2121 },
{ ',', 0x2122 },
{ '.', 0x2123 },
{ ',', 0x2124 },
{ '.', 0x2125 },
{ '.', 0x2126 },
{ ':', 0x2127 },
{ ';', 0x2128 },
{ '?', 0x2129 },
{ '!', 0x212a },
{ '\"', 0x212b },
{ '^', 0x2130 },
{ '_', 0x2132 },
{ '-', 0x213c },
{ '-', 0x213d },
{ '-', 0x213e },
{ '/', 0x213f },
{ '\\', 0x2140 },
{ '~', 0x2141 },
{ '|', 0x2143 },
{ '`', 0x2146 },
{ '\'', 0x2147 },
{ '\"', 0x2148 },
{ '\"', 0x2149 },
{ '(', 0x214a },
{ ')', 0x214b },
{ '(', 0x214c },
{ ')', 0x214d },
{ '[', 0x214e },
{ ']', 0x214f },
{ '{', 0x2150 },
{ '}', 0x2151 },
{ '<', 0x2152 },
{ '>', 0x2153 },
{ '[', 0x215a },
{ ']', 0x215b },
{ '+', 0x215c },
{ '-', 0x215d },
{ 'x', 0x215f },
{ '=', 0x2161 },
{ '$', 0x2170 },
{ '%', 0x2173 },
{ '#', 0x2174 },
{ '&', 0x2175 },
{ '*', 0x2176 },
{ '@', 0x2177 },
{ '*', 0x2179 },
{ '*', 0x217a },
{ '*', 0x2228 },
{ '=', 0x222e },
{ '0', 0x2330 },
{ '1', 0x2331 },
{ '2', 0x2332 },
{ '3', 0x2333 },
{ '4', 0x2334 },
{ '5', 0x2335 },
{ '6', 0x2336 },
{ '7', 0x2337 },
{ '8', 0x2338 },
{ '9', 0x2339 },
{ '\0', 0x0000 }
};
static struct {
char *string;
BYTE *real;
} ComposedEquivalents[] = {
{ "sha", "\x37\x63" },
{ "shi", "\x37" },
{ "shu", "\x37\x65" },
{ "she", "\x37\x27" },
{ "sho", "\x37\x67" },
{ "ja", "\x38\x63" },
{ "ji", "\x38" },
{ "ju", "\x38\x65" },
{ "je", "\x38\x27" },
{ "jo", "\x38\x67" },
{ "chi", "\x41" },
{ "ci", "\x41" },
{ "cha", "\x41\x63" },
{ "chu", "\x41\x65" },
{ "che", "\x41\x27" },
{ "cho", "\x41\x67" },
{ "tcha", "\x43\x41\x63" },
{ "tchi", "\x43\x41" },
{ "tci", "\x43\x41" },
{ "tchu", "\x43\x41\x65" },
{ "tche", "\x43\x41\x27" },
{ "tcho", "\x43\x41\x67" },
{ "tsu", "\x44" },
{ "tzu", "\x44" },
{ "+tsu", "\x43" },
{ "+tzu", "\x43" },
{ "dyi", "\x47\x23" },
{ "dyu", "\x49\x25" },
{ "fa", "\x55\x21" },
{ "fi", "\x55\x23" },
{ "fu", "\x55" },
{ "fe", "\x55\x27" },
{ "fo", "\x55\x29" },
{ "ye", "\x24\x27" },
{ "kwa", "\x2f\x21" },
{ "kwi", "\x2f\x23" },
{ "kwe", "\x2f\x27" },
{ "kwo", "\x2f\x29" },
{ "kua", "\x2f\x21" },
{ "kui", "\x2f\x23" },
{ "kue", "\x2f\x27" },
{ "kuo", "\x2f\x29" },
{ "gwa", "\x2f\x21" },
{ "gwi", "\x2f\x23" },
{ "gwe", "\x2f\x27" },
{ "gwo", "\x2f\x29" },
{ "gua", "\x2f\x21" },
{ "gui", "\x2f\x23" },
{ "gue", "\x2f\x27" },
{ "guo", "\x2f\x29" },
{ "n'", "\x73" },
{ "va", "[\x25\x74\x25\x21]" },
{ "vi", "[\x25\x74\x25\x23]" },
{ "vu", "[\x25\x74]" },
{ "ve", "[\x25\x74\x25\x27]" },
{ "vo", "[\x25\x74\x25\x29]" },
{ "`", "[\x21\x56]" }, /* These two are necessary because they */
{ "'", "[\x21\x57]" }, /* translate to non-ASCII equivalents */
{ "y=", "[\x21\x6f]" }, /* These two start with a letter */
{ "f-", "[\x21\x72]" },
{ NULL, NULL }
};
static char *direct[] = {
"+a", "a", "+i", "i", "+u", "u", "+e", "e", "+o", "o",
"ka", "ga", "ki", "gi", "ku", "gu", "ke", "ge", "ko", "go",
"sa", "za", "si", "zi", "su", "zu", "se", "ze", "so", "zo",
"ta", "da", "ti", "di", "+tu", "tu", "du", "te", "de", "to", "do",
"na", "ni", "nu", "ne", "no",
"ha", "ba", "pa", "hi", "bi", "pi", "hu", "bu", "pu", "he", "be", "pe",
"ho", "bo", "po",
"ma", "mi", "mu", "me", "mo",
"+ya", "ya", "+yu", "yu", "+yo", "yo",
"ra", "ri", "ru", "re", "ro",
"+wa", "wa", "wi", "we", "wo",
"n",
NULL
};
BOOL ConvertOK (FILEOPTIONS *f)
{
if (strlen(Typed) == 1 && strchr("AEIOU", Typed[0]) != NULL) return (TRUE);
if (SELPARA1(f) == NULL || SELPARA1(f) != SELPARA2(f)) return (FALSE);
return (TRUE);
}
static int FindDirect (char *s)
{
int i;
for (i = 0; direct[i] != NULL; i++)
if (!strcmp(direct[i], s)) return (i);
return (-1);
}
KANJI TranslateJAscii (KANJI ch, BOOL JtoA)
{
int i;
char cch;
if (JtoA) {
ch &= 0x7f7f;
for (i = 0; JAsciiEquivalents[i].ascii; i++) {
if (JAsciiEquivalents[i].kanji == ch) return (JAsciiEquivalents[i].ascii);
}
if (/* A */ 0x2341 <= ch && ch <= 0x235a /* Z */) return ('A' + (ch - 0x2341));
if (/* a */ 0x2361 <= ch && ch <= 0x237a /* z